package org.example.maven.mapper;

import org.apache.ibatis.annotations.*;
import org.example.maven.pojo.user.User;
import org.example.maven.pojo.user.list.AddUser;
import org.example.maven.pojo.user.list.SearchUser;
import org.example.maven.pojo.user.list.UserListTable;
import org.example.maven.pojo.user.person.PersonDetails;
import org.example.maven.pojo.user.person.PersonUpdatePassword;
import org.example.maven.pojo.utils.Ids;

import java.util.List;
import java.util.Map;

@Mapper
public interface userMapper {
    //根据用户名查找用户
    @Select("select *from user_role_view where username=#{username}")
    @Results({
            @Result(column = "role_key", property = "role")
    })
    User findUser(String username);

    //根据用户名获取用户id
    @Select("select id from user where username=#{username} and is_deleted=0")
    Integer getIdByUserName(String username);

    //根据id获取角色的权限
    @Select("select perm_key from user_role_permission where id=#{id}")
    List<String> getRolePermission(Integer id);

    //获取用户的listTable信息
    @Select("select id,username,mobile,dept_name,status,created_at,position_name,real_name from user_position_department")
    List<UserListTable> getAllUserList();


    //添加用户
    void addUser(AddUser addUser);

    //添加用户与角色的映射关系
    void addUserRole(String id,String[] roleId);

    //获取待编辑的用户信息
    @Select("select id,username,real_name,mobile,email,department_id,position_id,status from user where id=#{id}")
    AddUser getEditUser(Integer id);

    //获取用户对应角色的信息
    @Select("select role_id from user_role where user_id=#{id}")
    String[] getUserRole(Integer id);

    //更新用户信息
    void updateUser(AddUser addUser);

    //删除对应用户的权限
    @Delete("delete from user_role where user_id=#{id}")
    void deleteUserRole(String id);

    //逻辑删除用户
    void deleteUser(String[]id);

    //搜索特定的用户
    List<UserListTable> getSpecieUser(SearchUser searchUser);

    //获取total的总数
    Integer getUserCount(SearchUser searchUser);

    //获取用户名和密码
    @Select("select *from user")
    List<User> getUserPassword();

    //根据用户id获取密码
    @Select("SELECT password from user where id=#{id}")
    String getPasswordById(int id);

    //获取用户个人信息
    @Select("select *from personal_details where username=#{username}")
    PersonDetails getPersonalDetails(String username);

    //更新用户个人信息
    void updatePersonDetails(PersonDetails personDetails);

    //更新用户密码
    @Update("update user set password=#{newPassword} where id=#{id}")
    void updatePersonPassword(PersonUpdatePassword personUpdatePassword);

}
